//
//  AddCommentViewController.m
//  Reservation
//
//  Created by Wai Man Chan on 5/7/14.
//  Copyright (c) 2014 CHAN, Wai Man. All rights reserved.
//

#import "AddCommentViewController.h"
#import "Restaurant.h"
#import "LoginModel.h"

@interface AddCommentViewController ()

@end

@implementation AddCommentViewController
@synthesize restaurantID;
@synthesize segmentControl, heading, commentView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)close {
    NSMutableArray *arr = [[NSMutableArray alloc] initWithArray:self.tabBarController.viewControllers];
    [arr removeObject:self];
    self.tabBarController.viewControllers = arr;
}

- (IBAction)cancel:(id)sender {
    [self close];
}

#define CommentAddress @"http://happywaiman.dlinkddns.com/Reserve/Company/review.php?action=add&sid=%lld&uid=_uid&star=%d"
- (IBAction)sumbit:(id)sender {
    NSString *newAddress = [NSString stringWithFormat:CommentAddress, restaurantID, segmentControl.selectedSegmentIndex+1];
    [[LoginModel shareModel] queryWithAddress:newAddress andData:[commentView.text dataUsingEncoding:NSUTF8StringEncoding] withQuery:^(NSData *data) {
        
    } cancel:^{
        
    }];
    [self close];
}

@end
